import Vue from "vue";
import VueRouter from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "home",
    component: () => import("./Home"),
    meta: {
      title: "首页",
    },
  },
  {
    path: "/home-son",
    name: "home-son",
    component: () => import("./Home/son.vue"),
    meta: {
      title: "首页-子",
      keepAlivePages: ["home-sun"],
    },
  },
  {
    path: "/home-sun",
    name: "home-sun",
    component: () => import("./Home/sun.vue"),
    meta: {
      title: "首页-孙",
    },
  },
];
Vue.use(VueRouter);

const router = new VueRouter({
  mode: "hash",
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
});

export default router;
